var form = null;
var layer = null;
layui.use(['table', 'element', 'form', 'laydate', "code"], function () {
    form = layui.form;
    layer = layui.layer;
});


// 打开页面初始化默认值
var gateway_num = getCookie("flink-project-monitor-restart-num")
$('#gateway_num').val(gateway_num)

var gateway_id = getCookie("flink-project-monitor-restart-id")
$.get("/flink_config/getProjectById?id=" + gateway_id, function(req) {
    $('#alarm_status').val(req.alarm_status);
    $(":radio[name='testing_interval'][value='" + req.testing_interval + "']").prop("checked", "checked");
    $('#alarm_email').val(req.alarm_email);
});

function edit() {

    var gateway_num = $('#gateway_num').val()
    var alarm_status = $('#alarm_status').val()
    var testing_interval = $('input:radio[name="testing_interval"]:checked').val()
    var alarm_email = $('#alarm_email').val()

    if (testing_interval === undefined || testing_interval === '') {
        layer.msg('请选择检测间隔！');
        return
    }
    if (alarm_email === undefined || alarm_email === '') {
        layer.msg('请输入报警邮箱！');
        return
    }

    var load = layer.load(1, {shade: [0.1, '#000']});
    $.ajax({
        type: "POST",
        url: "/flink_config/alarm_edit",
        contentType: "application/json",
        data: JSON.stringify({
            "gateway_num": gateway_num,
            "alarm_status": alarm_status,
            "testing_interval": testing_interval,
            "alarm_email": alarm_email,
        }),
        success: function (req) {
            layer.close(load);
            if (req === 'success') {
                layer.msg('操作成功');
                window.setTimeout(function () {
                    xadmin.close();
                    parent.refresh();
                }, 1000);
            } else {
                layer.msg(req);
            }
        }
    });


}
